package studentmanagement;

import java.util.ArrayList;
import java.util.List;

public class Course {
    private String id;
    private String courseName;
    private String location;
    private String time;
    private Teacher teacher; // 授课教师（protected供子类访问）
    private int capacity; // 课程容量（新增）
    private List<Student> enrolledStudents = new ArrayList<>(); // 已选学生（新增）

    // 构造方法：增加课程容量参数
    public Course(String id, String courseName, String location, String time, int capacity) {
        this.id = id;
        this.courseName = courseName;
        this.location = location;
        this.time = time;
        this.capacity = capacity;
    }

    // 校验课程是否满员
    public boolean isFull() {
        return enrolledStudents.size() >= capacity;
    }

    // 新增：添加选课学生
    public void addStudent(Student student) {
        if (!enrolledStudents.contains(student)) {
            enrolledStudents.add(student);
        }
    }

    // 新增：移除退课学生
    public void removeStudent(Student student) {
        enrolledStudents.remove(student);
    }

    // getter和setter
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getCourseName() { return courseName; }
    public void setCourseName(String courseName) { this.courseName = courseName; }
    public String getLocation() { return location; }
    public void setLocation(String location) { this.location = location; }
    public String getTime() { return time; }
    public void setTime(String time) { this.time = time; }
    public Teacher getTeacher() { return teacher; }
    public void setTeacher(Teacher teacher) { this.teacher = teacher; }
    public int getCapacity() { return capacity; }
    public int getCurrentStudents() { return enrolledStudents.size(); }
}